package com.example.d10_homework.homework06;

public class GiftThread implements Runnable {
    private Gift gift;

    public GiftThread(Gift gift) {
        this.gift = gift;
    }

    @Override
    public void run() {
        String name = Thread.currentThread().getName();
        while (true) {
            synchronized (this) {
                int number = gift.getNumber();
                if (number < 10) {
                    break;
                }
                System.out.println(name + "正在送" + number + "份礼物");
                gift.setNumber(number - 1);
            }
        }
    }
}
